//
//  TSTableViewViewController.m
//  MirkoLibTest
//
//  Created by Mirko on 2017/3/31.
//  Copyright © 2017年 Mirko. All rights reserved.
//

#import "TSTableViewViewController.h"
#import "MCTextAutoFillService.h"
#import "TestTableAutoCell1TableViewCell.h"

@interface TSTableViewViewController () <MCTextAutoFillDelegate>

@property (nonnull, strong) MCTextAutoFillService *service;

@end

@implementation TSTableViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addRightBttonAction:nil];
    
    [TestTableAutoCell1TableViewCell class];
    
    // Do any additional setup after loading the view.
    self.service = [[MCTextAutoFillService alloc] init];
    [self.mcTableView registerNib:[UINib nibWithNibName:@"TestTableAutoCell1TableViewCell" bundle:nil] forCellReuseIdentifier:@"TestTableAutoCell1TableViewCell"];
    [self.mcTableView registerNib:[UINib nibWithNibName:@"TestTableAutoCell2TableViewCell" bundle:nil]  forCellReuseIdentifier:@"TestTableAutoCell2TableViewCell"];
    
    
    int counter = 20;
    for (int i = 0; i < counter; ++i) {
        [self.mcTableDataSource addObject:[NSString stringWithFormat:@"%d", counter]];
    }
}

-(void) handleRightBtnAction:(UIButton *)button
{
    [self.service removeAutoFillItem:nil];
    [self.mcTableView reloadData];
}

-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.service addAutoFillItem:self tablevView:self.mcTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mcTableDataSource.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat result = 0;
    if (indexPath.row % 2== 0) {
        result = 44;
    }
    else{
        result = 144;
    }
    return result;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    if (indexPath.row % 2== 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"TestTableAutoCell1TableViewCell"];
    }
    else{
        cell = [tableView dequeueReusableCellWithIdentifier:@"TestTableAutoCell2TableViewCell"];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

-(NSArray *) autoFillData:(UIViewController *) controller
{
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    int counter = 20;
    for (int i = 0; i < counter; ++i) {
        if (i % 2== 0) {
            NSString *string = [NSString stringWithFormat:@"%d", i];
            [arr addObject:@[string]];
        }
        else{
            NSString *string1 = [NSString stringWithFormat:@"%d", i];
            NSString *string2 = [NSString stringWithFormat:@"%d", i];
            [arr addObject:@[string1, string2]];
        }
    }
    return arr;
}

-(void) dealloc
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}


-(void) goBack:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
